<template>
  <div class="layout-container">
    <!-- 侧边栏 -->
    <el-aside width="220px" class="sidebar">
      <div class="logo">
        <img src="../assets/logo.png" alt="Logo" class="logo-img" v-if="false" />
        <h2>SMock</h2>
      </div>
      <el-menu
        :default-active="activeMenu"
        router
        class="menu"
        background-color="#304156"
        text-color="#bfcbd9"
        active-text-color="#409EFF"
      >
        <el-menu-item index="/mock">
          <el-icon><document /></el-icon>
          <span>Mock API管理</span>
        </el-menu-item>
        <el-menu-item index="/logs">
          <el-icon><list /></el-icon>
          <span>请求历史记录</span>
        </el-menu-item>
        <el-menu-item index="/import-export">
          <el-icon><upload /></el-icon>
          <span>导入导出</span>
        </el-menu-item>
      </el-menu>
      <div class="sidebar-footer">
        <span class="version">v1.0.0</span>
      </div>
    </el-aside>

    <!-- 主内容区 -->
    <el-container class="main-container">
      <!-- 头部 -->
      <el-header class="header">
        <div class="breadcrumb">
          <el-breadcrumb separator="/">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>{{ currentRoute.meta.title }}</el-breadcrumb-item>
          </el-breadcrumb>
        </div>
        <div class="header-right">
          <div class="server-status">
            <el-tag type="success" size="small" effect="dark">
              <el-icon class="status-icon"><circle-check /></el-icon>
              服务运行中
            </el-tag>
          </div>
          <div class="user-info">
            <el-dropdown trigger="click">
              <span class="user-dropdown">
                管理员 <el-icon><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item>
                    <el-icon><setting /></el-icon> 设置
                  </el-dropdown-item>
                  <el-dropdown-item divided>
                    <el-icon><switch-button /></el-icon> 退出
                  </el-dropdown-item>
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </div>
        </div>
      </el-header>

      <!-- 内容区 -->
      <el-main class="content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </el-main>

      <!-- 页脚 -->
      <el-footer class="footer" height="40px">
        <div class="footer-content">
          <span>© {{ new Date().getFullYear() }} SMock - 简单高效的API模拟工具</span>
        </div>
      </el-footer>
    </el-container>
  </div>
</template>

<script setup>
import { computed } from 'vue'
import { useRoute } from 'vue-router'
import { 
  Document, 
  List, 
  Upload, 
  ArrowDown, 
  Setting, 
  SwitchButton, 
  CircleCheck 
} from '@element-plus/icons-vue'

const route = useRoute()

// 当前路由信息
const currentRoute = computed(() => route)

// 当前激活的菜单
const activeMenu = computed(() => {
  return route.path
})
</script>

<style scoped>
.layout-container {
  height: 100vh;
  display: flex;
}

.sidebar {
  background-color: #304156;
  color: white;
  height: 100%;
  overflow-x: hidden;
  position: relative;
  transition: width 0.3s;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.logo {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  letter-spacing: 1px;
  background: linear-gradient(45deg, #409EFF, #67C23A);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-img {
  width: 32px;
  height: 32px;
  margin-right: 8px;
}

.menu {
  border-right: none;
  flex: 1;
}

.menu .el-menu-item {
  height: 50px;
  line-height: 50px;
}

.menu .el-menu-item.is-active {
  background-color: #263445 !important;
}

.sidebar-footer {
  padding: 10px 0;
  text-align: center;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.header {
  background-color: #fff;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.server-status {
  display: flex;
  align-items: center;
}

.status-icon {
  margin-right: 4px;
}

.content {
  padding: 20px;
  overflow-y: auto;
  background-color: #f5f7fa;
}

.user-dropdown {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 500;
}

.footer {
  background-color: #fff;
  border-top: 1px solid #e6e6e6;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #909399;
  font-size: 12px;
}

/* 页面过渡动画 */
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.3s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>